using System;

namespace dmWS
{
	/// <summary>
	/// 
	/// </summary>
	public class UserManage : KTManage
	{
		public UserManage()
		{
			
		}
			
		public string insertUser(string id, string username, string name)
		{
			string ris = "";
			try
			{
				string query = "insert into users(id, username) values ('"+id+"','"+username+"')";
				
				if (name!="")
					query = "insert into users(id, username, name) values ('"+id+"', '"+username+"', '"+name+"')";

				int done = this.Db.ExecuteCommand(query);

				if (done==0)
					ris = "Query not executed";
			}
			catch (Exception ex)
			{
				ris = ex.Message;
			}
			return ris;
		}

		public string changeField(string userid, string field, string newValue)
		{
			string ris = "";
			try
			{
				string query = "update users set "+field+"='"+newValue+"' where id="+userid;
				
				int done = this.Db.ExecuteCommand(query);

				if (done==0)
					ris = "Query not executed";
			}
			catch (Exception ex)
			{
				ris = ex.Message;
			}
			return ris;
		}

		public string deleteUser(string userid)
			  {
				  string ris = "";
				  try
				  {
					string query = "delete from users where id="+userid;
					int done = this.Db.ExecuteCommand(query);

					if (done==0)
						ris = "Query not executed";
				  }
				  catch (Exception ex)
				  {
					  ris = ex.Message;
				  }
				  return ris;
			  }

	}

}
